home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Menu / c / Extend < prev    next >
Text File  |  1995-07-08  |  2KB  |  62 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Menu.Extend.c
  12.     Author:  Copyright © 1993 Shaun Blackmore and Jason Williams
  13.     Version: 1.00 (30 Apr 1993)
  14.     Purpose: Extends a menu by adding entries to the bottom of it
  15. */
  16.  
  17. #include <stdlib.h>
  18.  
  19. #include "DeskLib:Error.h"
  20. #include "DeskLib:Screen.h"
  21. #include "DeskLib:Wimp.h"
  22. #include "DeskLib:Menu.h"
  23.  
  24. #include "MenuDefs.h"
  25.  
  26.  
  27. /* These two functions are defined in Menu.c.NewMenu */
  28. extern void Menu__CountItems(char *, int *, int *);
  29. extern BOOL Menu__Create(menu_item *, char *, int);
  30.  
  31.  
  32. extern menu_ptr Menu_Extend(menu_ptr menu, char *description)
  33. {
  34.   menu_ptr  newmenu;
  35.   int       maxwidth = 0, newitems = 0, lastitem = 0;
  36.   menu_item *item = (menu_item *) ((int) menu + sizeof(menu_block));
  37.  
  38.   Menu__CountItems(description, &newitems, &maxwidth);
  39.  
  40.   maxwidth *= 8 * screen_delta.x;
  41.   if (menu->width < maxwidth)
  42.     menu->width = maxwidth;
  43.  
  44.   while (!item[lastitem].menuflags.data.last)         /* Find the last item */
  45.     lastitem++;
  46.  
  47.   newmenu = realloc((void *) menu, sizeof(menu_block) +
  48.                              (sizeof(menu_item) * (lastitem + 1 + newitems)));
  49.   if (newmenu == NULL)
  50.     return((menu_ptr) Error_OutOfMemory(FALSE, "menus"));
  51.  
  52.   item = (menu_item *) ((int) newmenu + sizeof(menu_block));
  53.   item[lastitem].menuflags.data.last = FALSE;
  54.  
  55.   if (!Menu__Create(&item[lastitem + 1], description, newitems))
  56.     return(menu);
  57.  
  58.   item[lastitem + newitems].menuflags.data.last = TRUE;
  59.  
  60.   return(newmenu);
  61. }
  62.